package com.ifatter.asyn;

import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.ifatter.http.HttpNetClient;
import com.ifatter.model.RegiModel;

import android.os.AsyncTask;

public class RegiAsyn extends AsyncTask{
	String url="http://itickme.appsp0t.com/regist.action";
	String name;
	String password;
	String repass;
	String format="json";
	public RegiAsyn(String name,String password,String repass){
		this.name=name;
		this.password=password;
		this.repass=repass;
		
	}
	@Override
	protected Object doInBackground(Object... arg0) {
		// TODO Auto-generated method stub
		Map<String,String> map=new HashMap<String,String>();
		map.put("username",name);
		map.put("password", password);
		map.put("repass", repass);
		map.put("format", format);
		HttpNetClient client=new HttpNetClient();
		try {
			String res = client.asStringByPost(url, map);
			JSONObject jsonObject = new JSONObject(res);
			RegiModel regiModel=new RegiModel();
			regiModel.status=jsonObject.optString("status");
			regiModel.user=jsonObject.optString("user");
			regiModel.key=jsonObject.optString("key");
			regiModel.info=jsonObject.optString("info");
			return regiModel;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("----error");
			return null;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			System.out.println("----error");
			e.printStackTrace();
			return null;
		}
	}

}
